﻿namespace Example
{
    using System;

    using Newtonsoft.Json;

    using Xunit;

    public sealed class ProductFacts
    {
        [Fact]
        public void JsonConvert_SerializeObject()
        {
            var product = new Product
            {
                Id = 123,
                Unique = new Guid("7366efec-8d37-463d-a3f5-4dd65bd11e78"),
                Name = "Widget"
            };

            const string expected = "{\"Id\":123,\"Unique\":\"7366efec-8d37-463d-a3f5-4dd65bd11e78\",\"Name\":\"Widget\"}";
            var actual = JsonConvert.SerializeObject(product);

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void JsonConvert_DeserializeObject()
        {
            var expected = new Product
            {
                Id = 123,
                Unique = new Guid("7366efec-8d37-463d-a3f5-4dd65bd11e78"),
                Name = "Widget"
            };

            const string json = "{\"Id\":123,\"Unique\":\"7366efec-8d37-463d-a3f5-4dd65bd11e78\",\"Name\":\"Widget\"}";
            var actual = JsonConvert.DeserializeObject<Product>(json);

            Assert.Equal(expected, actual);
        }
    }
}